package series;

import java.util.Set;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Serie implements Comparable<Serie>{
	
	private int id;
	private String name;
	private Set<Season> seasons = new TreeSet<Season>();
	
	public Serie(int id, String title) {
		super();
		this.id = id;
		this.name = title;
	}

	public Serie() {
		super();
	}

	@Override
	public int compareTo(Serie o) {
		return name.compareTo(o.name);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	
	public Set<Season> getSeasons() {
		return seasons;
	}
	
	public void setSeasons(Set<Season> seasons) {
		this.seasons = seasons;
	}

	public void addSeasons(Season[] seasons) {
		for (Season season : seasons) {
			this.seasons.add(season);
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Serie other = (Serie) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}


	@Override
	public String toString() {
		return "Serie [id=" + id + ", name=" + name + "]";
	}
}
